package club.xyes.remotedisplay.jni;

import club.xyes.remotedisplay.screen.Screen12864;

/**
 * 2018/11/12 Create by 郭文梁
 * AbstractOLEDScreen
 * 基础显示实现
 *
 * @author 郭文梁
 * @date 2018/11/12
 */
@SuppressWarnings("all")
public abstract class AbstractOLEDScreen implements OLEDScreen {
    /*
     * 加载JNI库
     */
    static {
        SSD1306.loadLibrary("/usr/lib/SSD1306.so");
    }

    /**
     * 12864 IIC SSD1306 芯片驱动的 OLED12864
     */
    public static final String OLED_12864 = "12_864";

    /**
     * 获取一个实例
     *
     * @param name 显示器名称
     * @return 驱动对象
     */
    public static OLEDScreen getInstance(String name) {
        OLEDScreen screen;
        switch (name) {
            case OLED_12864:
                screen = new Screen12864();
                break;
            default:
                throw new IllegalArgumentException("Unknown screen type:" + name);
        }
        return screen;
    }

    @Override
    public void init() {
        SSD1306.displayBegin();
    }

    @Override
    public void fill(int[] data) {
        SSD1306.ssd1306DataArray(data, data.length);
    }

    @Override
    public void inverse(boolean inverse) {
        SSD1306.ssd1306InvertDisplay(inverse ? 1 : 0);
    }
}
